﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using PloobsEngine.Publishers;
using PloobsEngine.Physics.XJigLib;
using PloobsEngine.Entity;

namespace PloobsEngine.Behaviors
{
    public class SmoothCharacterMovimentationBehavior : IBehavior
    {        
        private SmoothMovimentationAction cma;
        private HardMovimentationUpdate hupdate;        

        public SmoothCharacterMovimentationBehavior(EngineStuff engine, CharacterObject character)
        {
            cma = new SmoothMovimentationAction(character);
            hupdate = new HardMovimentationUpdate(engine, this);
            hupdate.Start();
        }
        
        #region IBehavior Members                

        public void PerformBehavior(String state, object data)
        {
            SmothData sd =  data as SmothData;
            if( data != null)
            {
                cma.setAceleration(sd.Aceleration);
                cma.setRotationStep(sd.Rotation);
                cma.Action();
            }
        }

        #endregion

        private ISubject _sub = new ConcreteSubject();
        #region ISubject Members
        public int ObserverNumber()
        {
            return _sub.ObserverNumber();
        }

        public void Attach(IObserver obs)
        {
            _sub.Attach(obs);
        }

        public void Dettach(IObserver obs)
        {
            _sub.Dettach(obs);
        }

        public void DettachAll()
        {
            _sub.DettachAll();
        }

        public void Notify(object obj)
        {
            _sub.Notify(obj);
        }

        #endregion

        #region IBehavior Members


        public string BehaviorName
        {
            get { return NAME; }
        }
        public const String NAME = "SMOOTHCHARACTERMOVIMENTATIONBEHAVIOR";        
        public const String BEHAVIOR = "SMOOTH";
        #endregion

        #region IBehavior Members


        private IList<IAction> actionsList = new List<IAction>();
        public IList<IAction> Actions
        {
            get { return actionsList; }
        }

        #endregion

        #region IBehavior Members


        public void Release()
        {
            EntityMapper.getInstance().RemoveEntity(hupdate);
        }

        #endregion    
    }

    public class SmothData
    {
        public SmothData(float rotation, float speed)
        {
            this.Aceleration = speed;
            this.Rotation = rotation;
        }

        public float Rotation;
        public float Aceleration;
    }

}
